package com.zzf.concurrent.example.ticket.bean;

import lombok.extern.slf4j.Slf4j;

import java.util.LinkedList;

/**
 * @author GaoFeng2017
 * @date 2019/8/4 22:14
 */
@Slf4j
public class TicketRunnable implements Runnable {

    private static final int MAX = 50;
    private int currentIndex = 1;
    private LinkedList<Integer> ids = new LinkedList<>();

    @Override
    public void run() {
        while(currentIndex <= MAX) {

            int value = currentIndex++;
            log.info("{}开始叫号，当前号数为{}", Thread.currentThread().getName(), value);
            ids.add(value);
            try {
                Thread.sleep((long) (Math.random() * 100L));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        log.info("ids size is {}", ids.size());
    }
}
